/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package t5.controller;

import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import t5.model.Aluno;
import t5.model.AlunoDAO;
import t5.model.Disciplina;
import t5.view.JFrameTela;

/**
 *
 * @author Gabriel Lunardi
 */
public class Controller {

    private JFrameTela view;
    private List<Aluno> listAlunos = new AlunoDAO().buscarTodos();
    private List<Disciplina> listDiscObrigatorias = preencheDiscObrig();

    public Controller(JFrameTela view) {
        this.view = view;
    }

    public void pesquisar() {
        Aluno a = newFromView();
        List<Disciplina> ldiscFeitas = new AlunoDAO().listDisciplinasByAluno(a.getMatricula());
        System.out.println("Todas as disciplinas já feitas, incluindo DCGS:");
        for (Disciplina dfe : ldiscFeitas){
            System.out.println(dfe);
        }
        System.out.println("\n\n\nAluno já fez as seguinte disciplinas obrigatórias: ");
        for (Disciplina dfeita : ldiscFeitas){
            for (Disciplina dobrigatoria : listDiscObrigatorias){
                if (dfeita.getCodDiscip().equals(dobrigatoria.getCodDiscip())){
                    System.out.println(dfeita);
                }
            }
        }
    }

    public Aluno newFromView() {
        Aluno a = null;
        System.out.println(view.getjComboBox1().getSelectedItem());
        if (view.getjComboBox1().getSelectedItem() == null) {
            view.MostraErro("Você deve selecionar um aluno");
        } else {
            Aluno t = (Aluno) view.getjComboBox1().getSelectedItem();
            view.getjLabelNomeAluno().setText(t.getNome());
            view.getjLabelAnoIngresso().setText(t.getAnoIngresso());
            if (t.getDiscList().isEmpty()) {
                view.MostraErro("Este aluno ainda não concluiu nenhuma disciplina");
            }
            a = new Aluno((t.getMatricula()));
        }
        return a;
    }

    public void clearFields() {
        view.getjLabelAnoIngresso().setText("");
        view.getjLabelNomeAluno().setText("");
        view.getjComboBox1().setSelectedIndex(-1);
    }

    public void populaCombo() {
        for (Aluno a : listAlunos) {
            view.getjComboBox1().addItem(a);
        }
    }

    private List<Disciplina> preencheDiscObrig() {
        List<Disciplina> l = new ArrayList<Disciplina>();
        l.add(new Disciplina("MTM1019", "CÁLCULO A", 90, 1));
        l.add(new Disciplina("MTM1025", "GEOMETRIA ANALÍTICA", 60, 1));
        l.add(new Disciplina("ELC1010", "CIRCUITOS DIGITAIS", 60, 1));
        l.add(new Disciplina("ELC1064", "LÓGICA E ALGORITMOS", 60, 1));
        l.add(new Disciplina("ELC1065", "LABORATÓRIO DE PROGRAMAÇÃO I", 60, 1));
        l.add(new Disciplina("ELC1085", "INTRODUÇÃO A COMPUTAÇÃO", 30, 1));

        l.add(new Disciplina("MTM1040", "MATEMÁTICA DISCRETA", 60, 2));
        l.add(new Disciplina("MTM1018", "ÁLGEBRA LINEAR", 60, 2));
        l.add(new Disciplina("ELC1011", "ORGANIZAÇÃO DE COMPUTADORES", 60, 2));
        l.add(new Disciplina("ELC1066", "ESTRUTURAS DE DADOS", 60, 2));
        l.add(new Disciplina("ELC1067", "LABORATÓRIO DE PROGRAMAÇÃO II", 60, 2));
        l.add(new Disciplina("LTE1059", "LÍNGUA INGLESA INSTRUMENTAL I", 60, 2));

        l.add(new Disciplina("MTM1020", "CÁLCULO B", 90, 3));
        l.add(new Disciplina("STC303", "ESTATÍSTICA", 60, 3));
        l.add(new Disciplina("ELC1079", "ARQUITETURA DE COMPUTADORES", 60, 3));
        l.add(new Disciplina("ELC1068", "PESQUISA E ORDENAÇÃO DE DADOS", 60, 3));
        l.add(new Disciplina("ELC117", "PARADIGMAS DE PROGRAMAÇÃO", 60, 3));
        l.add(new Disciplina("LTE1060", "LÍNGUA INGLESA INSTRUMENTAL II", 60, 3));

        l.add(new Disciplina("FSC135", "ELETRICIDADE E MAGNETISMO", 90, 4));
        l.add(new Disciplina("MTM224", "MÉTODOS NUMÉRICOS COMPUTACIONAIS", 60, 4));
        l.add(new Disciplina("ELC1080", "SISTEMAS OPERACIONAIS", 60, 4));
        l.add(new Disciplina("ELC120", "PROJETO E ANÁLISE DE ALGORITMOS", 60, 4));
        l.add(new Disciplina("ELC119", "FUNDAMENTOS DE BD", 60, 4));
        l.add(new Disciplina("ELC1069", "ENGENHARIA DE SOFTWARE", 60, 4));

        l.add(new Disciplina("ELC1083", "LINGUAGENS FORMAIS", 45, 5));
        l.add(new Disciplina("ELC123", "COMUNICAÇÃO DE DADOS ", 60, 5));
        l.add(new Disciplina("ELC1015", "COMPUTAÇÃO GRÁFICA", 60, 5));
        l.add(new Disciplina("ELC1013", "LÓGICA DE PREDICADOS", 60, 5));
        l.add(new Disciplina("ELC131", "IMPLEMENTAÇÃO DE BD", 60, 5));
        l.add(new Disciplina("ELC133", "QUALIDADE DE SOFTWARE", 60, 5));

        l.add(new Disciplina("ELC1088", "IMPLEMENTAÇÃO DE LINGUAGENS DE PROGRAMAÇÃO", 60, 6));
        l.add(new Disciplina("ELC1017", "REDES DE COMPUTADORES", 75, 6));
        l.add(new Disciplina("ELC1076", "COMPUTADORES E SOCIEDADE", 60, 6));
        l.add(new Disciplina("ELC1008", "TEORIA DA COMPUTAÇÃO", 60, 6));
        l.add(new Disciplina("CAD1044", "EMPREENDEDORISMO", 60, 6));
        l.add(new Disciplina("XXXX", "DCG", 60, 6));

        l.add(new Disciplina("ELC1086", "METODOLOGIA CIENTÍFICA", 60, 7));
        l.add(new Disciplina("ELC1018", "SISTEMAS DISTRIBUÍDOS", 60, 7));
        l.add(new Disciplina("ELC408", "COMPILADORES", 60, 7));
        l.add(new Disciplina("ELC1014", "INTELIGÊNCIA ARTIFICIAL", 60, 7));
        l.add(new Disciplina("XXXX", "DCG", 60, 7));
        l.add(new Disciplina("XXXX", "DCG", 60, 7));

        l.add(new Disciplina("XXXX", "DCG", 60, 8));
        l.add(new Disciplina("XXXX", "DCG", 60, 8));
        l.add(new Disciplina("XXXX", "DCG", 60, 8));
        l.add(new Disciplina("ELC1084", "TRABALHO DE GRADUAÇÃO EM CC", 180, 8));

        return l;

    }

    public void PopulaInterface() {

        view.getjButton1().setText(listDiscObrigatorias.get(0).getCodDiscip());
        view.getjButton2().setText(listDiscObrigatorias.get(1).getCodDiscip());
        view.getjButton3().setText(listDiscObrigatorias.get(2).getCodDiscip());
        view.getjButton4().setText(listDiscObrigatorias.get(3).getCodDiscip());
        view.getjButton5().setText(listDiscObrigatorias.get(4).getCodDiscip());
        view.getjButton6().setText(listDiscObrigatorias.get(5).getCodDiscip());
        view.getjButton7().setText(listDiscObrigatorias.get(6).getCodDiscip());
        view.getjButton8().setText(listDiscObrigatorias.get(7).getCodDiscip());
        view.getjButton9().setText(listDiscObrigatorias.get(8).getCodDiscip());
        view.getjButton10().setText(listDiscObrigatorias.get(9).getCodDiscip());
        view.getjButton11().setText(listDiscObrigatorias.get(10).getCodDiscip());
        view.getjButton12().setText(listDiscObrigatorias.get(11).getCodDiscip());
        view.getjButton13().setText(listDiscObrigatorias.get(12).getCodDiscip());
        view.getjButton14().setText(listDiscObrigatorias.get(13).getCodDiscip());
        view.getjButton15().setText(listDiscObrigatorias.get(14).getCodDiscip());
        view.getjButton16().setText(listDiscObrigatorias.get(15).getCodDiscip());
        view.getjButton17().setText(listDiscObrigatorias.get(16).getCodDiscip());
        view.getjButton18().setText(listDiscObrigatorias.get(17).getCodDiscip());
        view.getjButton19().setText(listDiscObrigatorias.get(18).getCodDiscip());
        view.getjButton20().setText(listDiscObrigatorias.get(19).getCodDiscip());
        view.getjButton21().setText(listDiscObrigatorias.get(20).getCodDiscip());
        view.getjButton22().setText(listDiscObrigatorias.get(21).getCodDiscip());
        view.getjButton23().setText(listDiscObrigatorias.get(22).getCodDiscip());
        view.getjButton24().setText(listDiscObrigatorias.get(23).getCodDiscip());
        view.getjButton25().setText(listDiscObrigatorias.get(24).getCodDiscip());
        view.getjButton26().setText(listDiscObrigatorias.get(25).getCodDiscip());
        view.getjButton27().setText(listDiscObrigatorias.get(26).getCodDiscip());
        view.getjButton28().setText(listDiscObrigatorias.get(27).getCodDiscip());
        view.getjButton29().setText(listDiscObrigatorias.get(28).getCodDiscip());
        view.getjButton30().setText(listDiscObrigatorias.get(29).getCodDiscip());
        view.getjButton31().setText(listDiscObrigatorias.get(30).getCodDiscip());
        view.getjButton32().setText(listDiscObrigatorias.get(31).getCodDiscip());
        view.getjButton33().setText(listDiscObrigatorias.get(32).getCodDiscip());
        view.getjButton34().setText(listDiscObrigatorias.get(33).getCodDiscip());
        view.getjButton35().setText(listDiscObrigatorias.get(34).getCodDiscip());
        view.getjButton36().setText(listDiscObrigatorias.get(35).getCodDiscip());
        view.getjButton37().setText(listDiscObrigatorias.get(36).getCodDiscip());
        view.getjButton38().setText(listDiscObrigatorias.get(37).getCodDiscip());
        view.getjButton39().setText(listDiscObrigatorias.get(38).getCodDiscip());
        view.getjButton40().setText(listDiscObrigatorias.get(39).getCodDiscip());
        view.getjButton41().setText(listDiscObrigatorias.get(40).getCodDiscip());
        view.getjButton42().setText(listDiscObrigatorias.get(41).getCodDiscip());
        view.getjButton43().setText(listDiscObrigatorias.get(42).getCodDiscip());
        view.getjButton44().setText(listDiscObrigatorias.get(43).getCodDiscip());
        view.getjButton45().setText(listDiscObrigatorias.get(44).getCodDiscip());
        view.getjButton46().setText(listDiscObrigatorias.get(45).getCodDiscip());


    }
}
